package round79;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * User: Samuel
 * Date: 08-03-11
 * Time: 03:06 PM
 */
public class C {
    public static void main(String[] args) throws IOException {
        new C().run();
    }

    private void run() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String str = in.readLine();
        int k = Integer.parseInt(in.readLine());
        if (k >= str.length()) {
            System.out.println(0);
            System.out.println();
            System.exit(0);
        }
        Map<Character, Integer> occur = new TreeMap<Character, Integer> ();
        for (int i = 0; i < str.length(); i++) {
            char key = str.charAt(i);
            if (occur.containsKey(key)) {
                occur.put(key, occur.get(key) + 1);
            } else {
                occur.put(key, 1);
            }
        }
        int distinct = occur.size();
//        List<Character> del = new ArrayList<Character>();
        List<Pair> list = new ArrayList<Pair>();

        for (Character c: occur.keySet()) {
            Pair pair = new Pair();
            pair.c = c;
            pair.count = occur.get(c);
            list.add(pair);
        }
        int k2 = k;

        Map<Character, Integer> del = new HashMap<Character, Integer>();
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            Pair pair = list.get(i);
            if (k2 >= pair.count) {
                k2 -= pair.count;
                del.put(pair.c, pair.count);
            } else
                break;
        }
        int min = distinct - del.size();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char key = str.charAt(i);
            if (del.containsKey(key)) {
                Integer d = del.get(key);
                if (d - 1 == 0) {
                    del.remove(key);
                } else {
                    del.put(key, d - 1);
                }
                continue;
            }
            sb.append(key);
        }
        System.out.println(min);
        System.out.println(sb.toString());
    }

    class Pair implements Comparable<Pair> {
        Character c;
        int count;

        @Override
        public boolean equals(Object obj) {
            return super.equals(obj);
        }

        public int compareTo(Pair o) {
            return count - o.count;
        }
    }

}
